package com.example.bilibili_miaosha.controller;


import com.example.bilibili_miaosha.service.IUserService;
import com.example.bilibili_miaosha.vo.LoginVo;
import com.example.bilibili_miaosha.vo.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/login")
@Slf4j
public class LoginController {
    @Autowired
    private IUserService userService;



    /**
     * @Description:  页面跳转
     * @Param:  页面传递进来的参数loginVo（）
     * @return:  JSON,因为加了@ResponseBody注解，所以JSon会返回给前端，因为前端中layer.msg(data.message);所以会作为提示出现
     * @Author: 弓川
     * @Date: 2022/3/28
     **/
    @RequestMapping("/doLogin")
    @ResponseBody
    public RespBean doLogin(@Validated LoginVo loginVo, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        System.out.println(loginVo.toString());
        log.info("{}",loginVo);

        return userService.doLogin(loginVo,httpServletRequest,httpServletResponse);
    }

    @RequestMapping("/tologin")
    public String toLogin()
    {
        return "login";
    }
}
